package com.itheima.web.controller;

import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Name UserController
 * @Author BaiXin
 * @Date 2022-10-21 18:21
 */
@Controller
@RequestMapping("/users")
public class UserController {
    @Autowired
    private UserService userService;


    @PostMapping
    public String login(User user,HttpServletRequest request) {
        if (userService.login(user) != null) {
            System.out.println(user.getName());
            request.getSession().setAttribute("loginUser", user.getName());
            return "redirect:/pages/list.html";
        }else {
            //登录失败
            return "redirect:/pages/login.html";
        }

    }

}
